﻿using System;
using System.Collections.Generic;
using System.Text;

using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;

namespace SZ
{
  public   class GeometryManageClass
    {
        //创建多边形
        public IGeometry CreateRectangle(IEnvelope pEnvelop)
        {
            try
            {
                double xMin = pEnvelop.XMin;
                double xMax = pEnvelop.XMax;
                double yMin = pEnvelop.YMin;
                double yMax = pEnvelop.YMax;

                IPoint pPoint = null;
                object missing = Type.Missing;
                IPointCollection pPointCollection = new PolygonClass();

                pPoint = new PointClass();
                pPoint.PutCoords(xMin, yMin);
                pPointCollection.AddPoint(pPoint, ref missing, ref missing);

                pPoint = new PointClass();
                pPoint.PutCoords(xMax, yMin);
                pPointCollection.AddPoint(pPoint, ref missing, ref missing);

                pPoint = new PointClass();
                pPoint.PutCoords(xMax, yMax);
                pPointCollection.AddPoint(pPoint, ref missing, ref missing);

                pPoint = new PointClass();
                pPoint.PutCoords(xMin, yMax);
                pPointCollection.AddPoint(pPoint, ref missing, ref missing);

                IPolygon pPolygon = pPointCollection as IPolygon;
                pPolygon.Close();
                pPolygon.SimplifyPreserveFromTo();
                return pPolygon as IGeometry;
            }
            catch
            {
                return null;
            }
        }
    }
}
